package com.ruoyi.web.controller.webContent;

import java.util.List;

import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.webContent.domain.PlTeam;
import com.ruoyi.webContent.service.IPlTeamService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-07-11
 */
@Controller
@RequestMapping("/system/team")
public class PlTeamController extends BaseController
{
    private String prefix = "system/team";

    @Autowired
    private IPlTeamService plTeamService;

    @RequiresPermissions("system:team:view")
    @GetMapping()
    public String team()
    {
        return prefix + "/team";
    }

    @RequiresPermissions("system:team:view")
    @GetMapping("/teamVip")
    public String teamVip()
    {
        return prefix + "/teamVip";
    }

    @RequiresPermissions("system:team:view")
    @GetMapping("/teamForAdmin")
    public String teamForAdmin()
    {
        return prefix + "/teamForAdmin";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:team:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlTeam plTeam)
    {
        startPage();
//        ServletUtils.getRequest()
        List<PlTeam> list = plTeamService.selectPlTeamList(plTeam);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:team:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlTeam plTeam)
    {
        List<PlTeam> list = plTeamService.selectPlTeamList(plTeam);
        ExcelUtil<PlTeam> util = new ExcelUtil<PlTeam>(PlTeam.class);
        return util.exportExcel(list, "team");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:team:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlTeam plTeam)
    {
        return toAjax(plTeamService.insertPlTeam(plTeam));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PlTeam plTeam = plTeamService.selectPlTeamById(id);
        mmap.put("plTeam", plTeam);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:team:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlTeam plTeam)
    {
        return toAjax(plTeamService.updatePlTeam(plTeam));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:team:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(plTeamService.deletePlTeamByIds(ids));
    }


    @PostMapping( "/merge")
    @ResponseBody
    public AjaxResult merge(String ids)
    {
        return toAjax(plTeamService.merge(ids));
    }
}
